﻿using Candy.Model;
using Candy.Web.Data;
using GalaSoft.MvvmLight.Command;

namespace Candy.ViewModel
{
    public class GeneAnnotationEditViewModel : EntityEditViewModel<GeneAnnotationDto>
    {


        public GeneAnnotationEditViewModel(IDataService dataService, GeneAnnotationDto dto ) : base(dataService, dto, dataService.GeneAnnotations)
        {
           
        }


        private RelayCommand _delete;
        public RelayCommand Delete
        {
            get
            {
                return _delete ?? (_delete = new RelayCommand(ExecDelete, CanDelete));
            }
        }

        /// <summary>
        /// Checks whether the Delete command is executable
        /// </summary>
        private bool CanDelete()
        {
            return true;
        }

        /// <summary>
        /// Executes the Delete command 
        /// </summary>
        private void ExecDelete()
        {
            base.ConfirmAction(doit =>
            {
                if (doit)
                {
                    IsBusy = true;
                    base.Entities.Remove(this.Entity);
                    _dataService.SubmitAsync(op =>
                        {
                            IsBusy = false;
                            if (op.HasError)
                            {
                                base.HandleDomainError(op, "Deleting annotation failed.");
                            }
                        });
                }
            }, "Your are about to delet the current annotation.");

        }

    }
}
